//
//  LEAlertView+LE.m
//  CreditAddressBook
//
//  Created by LE on 15/12/14.
//  Copyright © 2015年 Lee. All rights reserved.
//

#import "LEAlertView+LE.h"
#import "CustomIOSAlertView.h"

@implementation LEAlertView (LE)

+ (void)showAlertViewWithTitles:(NSArray *)titles iconNames:(NSArray *)iconNames clickAtIndex:(ClickAtIndexBlock)clickAtIndex {
    LEAlertView *alertView = [[LEAlertView alloc] init];
    alertView.buttonTitles = titles;
    alertView.buttonImages = iconNames;
    [alertView setOnButtonTouchUpInside:^(LEAlertView *view, int buttonIndex) {
        clickAtIndex(buttonIndex);
    }];
    alertView.style = LEAlertStyleSheet;
    [alertView showToView:nil];
}

+ (void)showAlertViewWithButton:(NSString *)button cancelButton:(NSString *)cancelButton customView:(UIView *)customView showInView:(UIView *)view clickAtIndex:(ClickAtIndexBlock)clickAtIndex {
    LEAlertView *alertView = [[LEAlertView alloc] init];
    CGFloat ratio = customView.height/customView.width;
    CGFloat w = CYScreeSize.width - 32;
    CGFloat h = w * ratio;
    if (h > CYScreeSize.height - 55 - 32) {
        h = CYScreeSize.height - 55 - 32;
    }
    customView.frame = CGRectMake(0, 0, w, h);
    alertView.containerView = customView;
    alertView.buttonTitles = @[cancelButton, button];
    [alertView setOnButtonTouchUpInside:^(LEAlertView *view, int buttonIndex) {
        clickAtIndex(buttonIndex);
    }];
    alertView.style = LEAlertStyleAlert;
    [alertView showToView:view];
}

+ (void)showAlertCustomViewWithButton:(NSString *)button cancelButton:(NSString *)cancelButton customView:(UIView *)customView clickAtIndex:(ClickAtIndexBlock)clickAtIndex {
    CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
    CGFloat ratio = customView.height / customView.width;
    CGFloat w = CYScreeSize.width - 32;
    customView.frame = CGRectMake(0, 0, w, w*ratio);
    alertView.containerView = customView;
    if (button) {
        alertView.buttonTitles = @[cancelButton, button];
    } else {
        alertView.buttonTitles = @[cancelButton];
    }
    
    [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
        clickAtIndex(buttonIndex);
    }];
    [alertView show];
}
/**
 *  展示自定义dialogView
 */
+ (instancetype)showCustomDialogView:(UIView *)dialogView showInView:(UIView *)view {
    LEAlertView *alertView = [[LEAlertView alloc] init];
    alertView.dialogView = dialogView;
    [alertView showToView:view];
    return alertView;
}
@end
